<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>物资管理</title>
    <jsp:include page="/WEB-INF/view/commons/css.jsp" />
</head>
<body >
<div id="main-container" class="container-fluid">
    <form  action="bizMaterialsManage/${action eq "create" ?"save":"update"}" name="inputForm" id="inputForm" method="post" class="form-horizontal">
    <input name="id" id="id" value="${entity.id}" type="hidden" />
    <input name="materialsCode" value="${entity.materialsCode}" type="hidden" />
    <div class="form-group">
        <label class="col-sm-1 control-label">物资名称：</label>
        <div class="col-md-3">
            <input type="text" class="form-control" name="materialsName" value="${entity.materialsName}" placeholder="物资名称">
        </div>
        <div class="col-sm-1"><span style="color: red">*</span></div>
    </div>
    <div class="form-group">
        <label class="col-sm-1 control-label">物资类别：</label>
        <div class="col-md-3">
                <d:select name="materialsType" list="${materialsTypes}" selected="${entity.materialsType}"/>
                <button type="button" onclick="addMaterial()" class="btn btn-sm btn-success link_add" data-title="新增物资类别"><i class="fa fa-plus"></i> 新增物资类别</button>
        </div>
        <div class="col-sm-1"><span style="color: red">*</span></div>
        <label class="col-sm-1 control-label">规格：</label>
        <div class="col-md-3">
            <input type="text" class="form-control" name="specification" value="${entity.specification}" placeholder="规格">
        </div>
        <div class="col-sm-1"><span style="color: red"></span></div>
    </div>
    <div class="form-group">
        <label class="col-sm-1 control-label">单位：</label>
        <div class="col-md-3">
            <d:select name="unit" list="${units}" selected="${entity.unit}"/>
            <button type="button" onclick="addUnit()" class="btn btn-sm btn-success link_add" data-title="新增物资单位"><i class="fa fa-plus"></i> 新增物资单位</button>
        </div>
        <div class="col-sm-1"><span style="color: red">*</span></div>
        <label class="col-sm-1 control-label">状态：</label>
        <div class="col-md-3">
           <%--  <d:select name="curStatus" list="${curStatus}" selected="${1}" /> --%>
           <d:radio list="${curStatus}" name="curStatus" selected="${entity.curStatus}" ></d:radio>
        </div>
        <div class="col-sm-1"><span style="color: red">*</span></div>
    </div>
    <div class="form-group">
        <div class="col-sm-offset-1 col-sm-2">
            <button id="saveBtn" type="submit" class="btn btn-sm btn-primary"><i class="fa fa-floppy-o"></i> 提交</button>
            <button type="button" class="btn btn-sm link_close"><i class="fa fa-close"></i> 关闭</button>
        </div>
    </div>
    </form>
</div><!--/#main-container-->

<!-- script start -->
<jsp:include page="/WEB-INF/view/commons/js.jsp" />
<script type="text/javascript">
    $(document).ready(function(e) {
        var options = {
            rules:{
                materialsName : { required : true, maxlength : 50 },
                specification : { required : false, maxlength : 20 }, 
                materialsType : { required : true, maxlength : 10 },
                unit : { required : true, maxlength : 10 },
                curStatus:{ required : true, maxlength : 10 },
            },
            submitHandler:function(form){
                $(form).ajaxSubmit({
                    type:'post',
                    dataType:'json',
                    success:function(data){
                    	if(data.duplicate_key){
                        	layer.alert(data.msg);
                        }
                    	if(data.success){
                            $('#searchBtn', parent.document).click();
                            closeIframe();
                        }else{
                            layer.alert(data.msg);
                        }
                    }
                });
            }
        };
       $("#inputForm").validate(options); 
    });
</script>

<script type="text/javascript">
function addMaterial(){
	layer.prompt({title: '类别名称',maxlength: 10, formType: 3},function(text,index){
        $.ajax({
            type: "POST",
            url: 'sysMaterialsType/save',
            data: {type_name:text},
            cache: false,
            success: function(data){
            	if(data.duplicate_key){
                	layer.alert(data.msg);
                }
            	if(data.success){
            		window.location.href='bizMaterialsManage/create';
                }else{
                    layer.alert(data.msg);
                }
                
            }
        });
    });
}

function addUnit(){
	layer.prompt({title: '单位名称',maxlength: 10, formType: 3},function(text,index){
        $.ajax({
            type: "POST",
            url: 'sysMaterialsUnit/save',
            data: {unit_name:text},
            cache: false,
            success: function(data){
            	if(data.duplicate_key){
                	layer.alert(data.msg);
                }
            	if(data.success){
            		window.location.href='bizMaterialsManage/create';
                }else{
                    layer.alert(data.msg);
                }
            }
        });
    });
}
</script>

<!-- script end -->
</body>
</html>
